package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.ProjectExperience;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


public class ProjectExperienceAction extends ActionSupport {
    public ProjectExperience projectexperience;



    public String ProjectExperience(){
        String Belong= NullChange.NullChange(projectexperience.getBelong());
        String ProjectName=NullChange.NullChange(projectexperience.getProjectName());
        String ProjectDes=NullChange.NullChange(projectexperience.getProjectDes());
        String Duty=NullChange.NullChange(projectexperience.getDuty());
        JSONObject json=new JSONObject();
        json.put("Belong",Belong);
        json.put("ProjectName",ProjectName);
        json.put("ProjectDes",ProjectDes);
        json.put("Duty",Duty);
        String jsonString =json.toJSONString();
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");

        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        boolean res= UserResumeDAO.updataProjectExperience(jsonString,UserID);
        if(res){
            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }

    }

    public ProjectExperience getProjectexperience() {
        return projectexperience;
    }

    public void setProjectexperience(ProjectExperience projectexperience) {
        this.projectexperience = projectexperience;
    }
}
